require 'watir'
include Watir
require 'test/unit'
require '../watir.config.rb'
require '../resources/functions.rb'
require 'win32ole'
require 'win32/process'

class TC_GroupForum_test < Test::Unit::TestCase
   
    def startup
      $GroupCategoryName= 'GroupCategory1'
      $GroupCategoryDescription = 'This is the first group category'
      $HubName = 'Group1'
      $AppKey = 'GroupAppKey1'
      $HubDescription = 'This is the first group'
      $Description = 'This is to test forum options for groups'
      $Subject = 'ForumGroup1'
      $SubjectEdit = $Subject+'_Edit'
      $PostDescription = 'This is the first forum post in forum groups'
      $PostDescriptionEdit = $PostDescription +'_Edit'
      $Tags= 'Forums,Groups,Posts'
      $TagsEdit =$Tags+',TagEdit'
      $UserName = 'User1'
      $UserPassword = 'pass123'
      $UserEmail = 'user@mailservice.com'
      $Member = 'User1'
      $Comments = 'Testing Comments'
      $VideoUrl ='http://www.youtube.com/watch?v=16fqhrPXiO8'
      $VideoWidth ='12'
      $VideoHeight ='15'
      $VideoDuration ='9:15'
      $Reply ='Re:'+ $SubjectEdit+'Reply'
      $ReplyContent =$PostDescriptionEdit +','+' '+'Reply'
      $EditNotes ='Testing Edits'
      $DeleteReason = 'Testing Deletes for Forums'
      $Request = 'Hello wondering if we can be friends'
      $EmailSubject = 'Testing Email'
      $EmailContent = 'Testing Email for forums'
      $Message = 'Message Testing for forums'
      $MessageSubject  = 'Testing the email for forums'
      $PollTitle = 'Testing Using Watir'
      $PollDescription ='Testing Community Server using Watir fetches results which are ...  '
      $Answer1 ='Good'
      $Answer2 = 'Fine'
      $Answer3 = 'Ok'
      $ExpireAfterDays = '30'
      @@ie = Watir::IE.start($SITE_URL)
    end
    
    def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
    end
    
    def test_0000
        require 'win32/process'
        $pid = Process.create(
        :app_name      => 'ruby ../resources/clickers.rb',
        :creation_flags  => Process::DETACHED_PROCESS
        ).process_id

    end  
    
    def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))		
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
        ie.link(:text, 'Sign in').click
        assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
        ie.text_field(:id, /username$/).value = $ADMIN_USER
        assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
        ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
        assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
        if(ie.button(:id, /loginButton$/).exists?)
          ie.button(:id, /loginButton$/).click
        else
        ie.link(:id, /loginButton$/).click
        end
        test_01_verifyHomeText
    end
    
    def test_06_verifyControlPanel
        assert(ie.link(:text, /Control Panel/).exists?)
        ie.link(:text, /Control Panel/).click
        assert(ie.contains_text(/Announcements/))
        assert(ie.link(:text, /System Administration/).exists?)
        ie.link(:text, /System Administration/).click
        assert(ie.contains_text(/Announcements/))
    end
    
    def test_07_verifyControlPanelLinks
        assert_equal $SITE_URL + 'controlpanel/', ie.link(:text, 'Dashboard').href
        assert_equal $SITE_URL + 'controlpanel/setup.aspx', ie.link(:text, 'Administration').href
        assert_equal $SITE_URL + 'controlpanel/BlogAdmin/', ie.link(:text, 'Blog Administration').href
        assert_equal $SITE_URL + 'controlpanel/MediaGalleryAdmin/', ie.link(:text, 'Media Galleries Administration').href
        assert_equal $SITE_URL + 'controlpanel/Forums/', ie.link(:text, 'Forum Administration').href
        assert_equal $SITE_URL + 'controlpanel/HubAdmin/', ie.link(:text, 'Group Administration').href
        assert_equal $SITE_URL + 'controlpanel/Membership/membersearch.aspx?SelectedNavItem=BrowseMembers', ie.link(:text, 'Membership Administration').href
        assert_equal $SITE_URL + 'controlpanel/Settings/default.aspx', ie.link(:text, 'Site Administration').href
    end
    
    def test_08_navigateToGroupAdministration
        ie.goto($SITE_URL + 'controlpanel/HubAdmin/')
        assert(ie.contains_text(' Group Administration '))      
      end  
      
    def test_09_verifyLinksExist
      # Make sure that all of the links exist
        assert(ie.link(:text, 'Log Out').exists?)
        assert(ie.link(:text, 'Help').exists?)
        assert(ie.link(:text, 'Go to Site').exists?)
        assert(ie.link(:text, 'Dashboard').exists?)
        assert(ie.link(:text, 'Administration').exists?)
        assert(ie.link(:text, 'Group Administration').exists?)
        assert(ie.link(:text, 'Telligent').exists?)
    end
      
    def test_10_navigateToAddCategory
        ie.goto($SITE_URL +'controlpanel/HubAdmin/groups.aspx')
        assert(ie.button(:id,/NewGroup$/).exists?)
        ie.button(:id,/NewGroup$/).click
        sleep 5
        assert(ie.frame(:index,1).text_field(:id,/GroupName$/).exists?)
        ie.frame(:index,1).text_field(:id,/GroupName$/).value =$GroupCategoryName
        assert(ie.frame(:index,1).text_field(:id,/GroupDesc$/).exists?)
        ie.frame(:index,1).text_field(:id,/GroupDesc$/).value =$GroupCategoryDescription
        assert(ie.frame(:index,1).link(:id,/SaveButton$/).exists?)
        ie.frame(:index,1).link(:id,/SaveButton$/).click
        sleep 3
      end
      
    def test_11_createUser 
        ie.goto($SITE_URL +'controlpanel/membership/UserAdd.aspx')
        assert(ie.text_field(:id,/username$/).exists?)
        ie.text_field(:id,/username$/).value = $UserName
        assert(ie.text_field(:id,/password$/).exists?)
        ie.text_field(:id,/password$/).value = $UserPassword
        password=ie.text_field(:id,/password$/).value
        assert(ie.text_field(:id,/password2$/).exists?)
        ie.text_field(:id,/password2$/).value =password
        assert(ie.text_field(:id,/email$/).exists?)
        ie.text_field(:id,/email$/).value = $UserEmail
        assert(ie.select_list(:id,/timezone$/).exists?)
        ie.select_list(:id,/timezone$/).select('(GMT +05:00) Islamabad, Karachi, Tashkent')
        assert(ie.button(:name,/createButton$/).exists?)
        ie.button(:name,/createButton$/).click
    end
      
   
    def test_12_navigateToCreateGroup
        ie.goto($SITE_URL+'groups/')
        sleep 3
        assert(ie.link(:text,'Create a new group').exists?)
        ie.link(:text,'Create a new group').click
        sleep 3
        assert(ie.text_field(:id,/HubName$/).exists?)
        ie.text_field(:id,/HubName$/).value =$HubName
        $HubName1 =  $HubName.downcase
        sleep 3
        ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_bcr_bcr_ctl00_ctl02_HubDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$HubDescription+"')")
        sleep 3
        assert(ie.radio(:id,/HubType_0$/).exists?)
        assert(ie.radio(:id,/HubType_1$/).exists?)
        assert(ie.radio(:id,/HubType_2$/).exists?)
        ie.radio(:id,/HubType_0$/).set
        assert(ie.select_list(:id,/HubGroup$/).exists?)
        sleep 2
        ie.select_list(:id,/HubGroup$/).select($GroupCategoryName)
        assert(ie.button(:id,/Create$/).exists?)
        ie.button(:id,/Create$/).click
      end
      
    def test_14_EditGroup
        sleep 5
        ie.goto($SITE_URL+'/groups/'+$HubName1+'/edit.aspx')
        # Forum Options
        assert(ie.checkbox(:id,/EnableModeration$/).exists?)
        ie.checkbox(:id,/EnableModeration$/).set
        # Save 
        sleep 2
        assert(ie.button(:id,/Save$/).exists?)
        sleep 2
        ie.button(:id,/Save$/).click     
      end
      
    def test_15_navigateToaddMember
      sleep 2
      ie.goto($SITE_URL+'groups/')
      sleep 2
      ie.goto($SITE_URL+'groups/'+$HubName1+'/members.aspx')
      sleep 2
      assert(ie.text_field(:id,/UserName/).exists?)
      sleep 2
      ie.text_field(:id,/UserName/).value = $Member
      assert(ie.select_list(:id,/MembershipType$/).exists?)
      sleep 2
      ie.select_list(:id,/MembershipType$/).select('Manager')
      sleep 2
      assert(ie.button(:value,'Add Member').exists?)
      ie.button(:value,'Add Member').click
      sleep 5
    end
    
    def test_16_createForumPost
        test_02_verifyLoginLinksExist
        test_03_navigateToLogin
        ie.text_field(:id, /username$/).value = $UserName
        ie.text_field(:id, /password$/).value = $UserPassword
        if(ie.button(:id, /loginButton$/).exists?)
          ie.button(:id, /loginButton$/).click
        else
        ie.link(:id, /loginButton$/).click
        end
        sleep 5
        ie.goto($SITE_URL+'groups/')
        sleep 2
        assert(ie.link(:text, $HubName).exists?)
        sleep 2
        ie.link(:text, $HubName).click
        sleep 5
        assert(ie.link(:text,'Discussions').exists?)
        ie.link(:text,'Discussions').click
        #~ ie.goto($SITE_URL+'groups/'+$HubName1 +'/forum/default.aspx')
        sleep 2
        if(!ie.text_field(:id,/PostForm_ctl05_PostSubject$/).exists?)
        sleep 5
        test_02_verifyLoginLinksExist
        test_03_navigateToLogin
        test_04_populateLoginForm
        test_05_submitLoginForm
        ie.goto($SITE_URL+'groups/')
        assert(ie.link(:text, $HubName).exists?)
        sleep 2
        ie.link(:text, $HubName).click
        sleep 5
        ie.goto($SITE_URL+'/groups/'+$HubName1+'/edit.aspx')
        sleep 5
        assert(ie.button(:id,/Save$/).exists?)
        sleep 2
        ie.button(:id,/Save$/).click  
        test_02_verifyLoginLinksExist
        test_03_navigateToLogin
        ie.text_field(:id, /username$/).value = $UserName
        ie.text_field(:id, /password$/).value = $UserPassword
        ie.button(:id, /loginButton$/).click
        sleep 5
        ie.goto($SITE_URL+'groups/')
        sleep 2
        assert(ie.link(:text, $HubName).exists?)
        sleep 2
        ie.link(:text, $HubName).click
        sleep 5
        assert(ie.link(:text,'Discussions').exists?)
        sleep 2
        ie.link(:text,'Discussions').click
        sleep 3
        assert(ie.link(:text,'Write a New Post').exists?)
        sleep 3
        ie.link(:text,'Write a New Post').click      
        else
        assert(ie.link(:text,'Write a New Post').exists?)
        ie.link(:text,'Write a New Post').click
        end
        # Compose
        assert(ie.text_field(:id,/PostForm_ctl05_PostSubject$/).exists?)
        sleep 3
        ie.text_field(:id,/PostForm_ctl05_PostSubject$/).value =$Subject
        sleep 5
        ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_PostBody_ctl00_Editor').execCommand('mceSetContent',false,'"+$PostDescription+"')")
        # Options
        ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.GetTabAtIndex(1))")
        assert(ie.checkbox(:id,/IsLocked$/).exists?)
        ie.checkbox(:id,/IsLocked$/).clear
        assert(ie.select_list(:id,/PinnedPost$/).exists?)
        ie.select_list(:id,/PinnedPost$/).select('6 Months')
        # Video
        ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.GetTabAtIndex(2))")
        assert(ie.checkbox(:id,/IncludeVideo$/).exists?)
        ie.checkbox(:id,/IncludeVideo$/).set
        sleep 2
        assert(ie.text_field(:id,/VideoUrl$/).exists?)
        ie.text_field(:id,/VideoUrl$/).value =$VideoUrl
        assert(ie.text_field(:id,/VideoImageUrl$/).exists?)
        ie.text_field(:id,/VideoImageUrl$/).value =$VideoUrl
        assert(ie.text_field(:id,/VideoDuration$/).exists?)
        ie.text_field(:id,/VideoDuration$/).value =$VideoDuration
        assert(ie.text_field(:id,/VideoWidth$/).exists?)
       ie.text_field(:id,/VideoWidth$/).value =$VideoWidth
       assert(ie.text_field(:id,/VideoHeight$/).exists?)
      ie.text_field(:id,/VideoHeight$/).value =$VideoHeight
      # Poll
      ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.GetTabAtIndex(3))")
      assert(ie.checkbox(:id,/IncludePoll$/).exists?)
      ie.checkbox(:id,/IncludePoll$/).set
      sleep 2
      assert(ie.text_field(:id,/PollTitle$/).exists?)
      ie.text_field(:id,/PollTitle$/).value =$PollTitle
      sleep 2
      ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_PollSubForm_ctl00_PollContainer_ctl00_PollDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$PollDescription+"')")
      assert(ie.text_field(:id,/NewAnswer$/).exists?)
      ie.text_field(:id,/NewAnswer$/).value =$Answer1
      assert(ie.button(:id,/AddButton$/).exists?)
      ie.button(:id,/AddButton$/).click
      assert(ie.text_field(:id,/NewAnswer$/).exists?)
      ie.text_field(:id,/NewAnswer$/).value =$Answer2
      assert(ie.button(:id,/AddButton$/).exists?)
      ie.button(:id,/AddButton$/).click
      assert(ie.text_field(:id,/NewAnswer$/).exists?)
      ie.text_field(:id,/NewAnswer$/).value =$Answer3
      assert(ie.button(:id,/AddButton$/).exists?)
      ie.button(:id,/AddButton$/).click
      assert(ie.text_field(:id,/ExpireAfterDays$/).exists?)
      ie.text_field(:id,/ExpireAfterDays$/).value =$ExpireAfterDays
      # Related 
      ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.GetTabAtIndex(4))")
      sleep 3
      # Preview
      ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.GetTabAtIndex(5))")
      sleep 5
      assert(ie.button(:id,/PostForm_ctl05_PostButton$/).exists?)
      ie.button(:id,/PostForm_ctl05_PostButton$/).click 
    end   
  
    def test_17_moderatePost
       test_02_verifyLoginLinksExist
      test_03_navigateToLogin
      test_04_populateLoginForm
      test_05_submitLoginForm
      sleep 2
      ie.goto($SITE_URL+'groups/'+$HubName1 +'/forum/default.aspx')
      sleep 3
      assert(ie.link(:text,$Subject).exists?)
      sleep 2
      ie.link(:text,$Subject).click
      sleep 2
      #~ # The functionality is not working random error for lock and moderate user
      #~ ie.link(:text, 'Moderate').click
      #~ sleep 5
      #~ # Lock
      #~ assert(ie.cell(:text, 'Lock').exists?)
      #~ sleep 3
      #~ ie.cell(:text, 'Lock').click 
      #~ sleep 5
      #~ ie.link(:text, 'Moderate').click
      #~ sleep 5
      #~ assert(ie.cell(:text, 'Unlock').exists?)
      #~ sleep 3
      #~ ie.cell(:text, 'Unlock').click   
      #~ sleep 5
      #~ ie.link(:text, 'Moderate').click
      #~ sleep 5
      #~ # Moderate User
      #~ assert(ie.cell(:text, 'Moderate User').exists?)
      #~ sleep 3
      #~ ie.cell(:text, 'Moderate User').click 
      #~ sleep 5
      #~ ie.link(:text, 'Moderate').click
      #~ sleep 5
      #~ assert(ie.cell(:text, 'Unmoderate User').exists?)
      #~ sleep 3
      #~ ie.cell(:text, 'Unmoderate User').click   
      #~ sleep 5
    end
    
  def test_18_contact
      ie.link(:text, 'Contact').click
      sleep 5
      assert(ie.cell(:text, 'Add '+$UserName +' as a friend').exists?)
      sleep 3
      ie.cell(:text, 'Add '+ $UserName +' as a friend').click   
      sleep 5
      ie.ie.Document.ParentWindow.execscript("Telligent_Modal._modalIframe.contentWindow.tinyMCE.get('ctl00_bcr_ctl01_ctl02_Message_ctl00_Editor').execCommand('mceSetContent', false,'"+$Request+"')")
      sleep 3
      assert(ie.frame(:index,1).button(:id,/SendButton$/).exists?)
      ie.frame(:index,1).button(:id,/SendButton$/).click
      sleep 3
      ie.link(:text, 'Contact').click
      sleep 5
      assert(ie.cell(:text, 'Remove '+$UserName+' from my friend list').exists?)
      sleep 3
      ie.cell(:text, 'Remove '+$UserName+' from my friend list').click   
      sleep 5
      ie.link(:text, 'Contact').click
      sleep 5
      assert(ie.cell(:text, 'Send '+$UserName+' an email').exists?)
      sleep 3
      ie.cell(:text, 'Send '+$UserName+' an email').click   
      sleep 5
      assert(ie.frame(:index,1).text_field(:id,'ctl00_bcr_ctl01_ctl00_Subject').exists?)
      ie.frame(:index,1).text_field(:id,'ctl00_bcr_ctl01_ctl00_Subject').value =$EmailSubject
      ie.ie.Document.ParentWindow.execscript("Telligent_Modal._modalIframe.contentWindow.tinyMCE.get('ctl00_bcr_ctl01_ctl00_Message_ctl00_Editor').execCommand('mceSetContent', false,'"+$EmailContent+"')")
      assert(ie.frame(:index,1).button(:id,/SendButton$/).exists?)
      ie.frame(:index,1).button(:id,/SendButton$/).click
      sleep 5
      ie.link(:text, 'Contact').click
      sleep 5
      assert(ie.cell(:text, 'Start a conversation with '+$UserName).exists?)
      sleep 3
      ie.cell(:text, 'Start a conversation with '+$UserName ).click   
      sleep 5
      assert(ie.frame(:index,1).text_field(:id,'ctl00_bcr_CreateConversationForm_ctl02_MessageSubject').exists?)
      ie.frame(:index,1).text_field(:id,'ctl00_bcr_CreateConversationForm_ctl02_MessageSubject').set($MessageSubject)
      ie.ie.Document.ParentWindow.execscript("Telligent_Modal._modalIframe.contentWindow.tinyMCE.get('ctl00_bcr_CreateConversationForm_ctl02_Message_ctl00_Editor').execCommand('mceSetContent', false,'"+$Message+"')")
      assert(ie.frame(:index,1).button(:id,/SaveButton$/).exists?)
      ie.frame(:index,1).button(:id,/SaveButton$/).click
      sleep 5
    end
    
    # The functionality is not working  
    #~ def test_18_addPostAsFavorite
      #~ ie.link(:text, 'Favorites').click
      #~ sleep 3
      #~ assert(ie.cell(:text, 'Add this post as a favorite').exists?)
      #~ assert(ie.cell(:text, 'Add this forum as a favorite').exists?)
      #~ ie.cell(:text, 'Add this post as a favorite').click      
      #~ sleep 3
      #~ ie.link(:text, 'Favorites').click
      #~ sleep 3
      #~ assert(ie.cell(:text, 'Remove this post from favorites').exists?)
      #~ assert(ie.cell(:text, 'Add this forum as a favorite').exists?)
      #~ ie.cell(:text, 'Add this forum as a favorite').click
      #~ sleep 3
      #~ ie.link(:text, 'Favorites').click
      #~ sleep 3
      #~ assert(ie.cell(:text, 'Remove this post from favorites').exists?)
      #~ # Add this forum as a favorite is not working as desired 
      #~ #assert(ie.cell(:text, 'Remove this forum from favorites').exists?)
      #~ #ie.cell(:text, 'Remove this forum from favorites').click
      #~ sleep 3
      #~ ie.link(:text, 'Favorites').click      
      #~ sleep 3
      #~ ie.cell(:text, 'Remove this post from favorites').click
      #~ sleep 3
      #~ ie.link(:text, 'Favorites').click
      #~ sleep 3
      #~ assert(ie.cell(:text, 'Add this post as a favorite').exists?)
      #~ assert(ie.cell(:text, 'Add this forum as a favorite').exists?)
  #~ end
  def test_19_EditPost
      assert(ie.link(:href,/editpost.aspx/).exists?)
      ie.link(:href,/editpost.aspx/).click
      sleep 4 
      assert(ie.text_field(:id,/PostSubject$/).exists?)
      ie.text_field(:id,/PostSubject$/).value = $SubjectEdit
      sleep 5
      ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_PostBody_ctl00_Editor').execCommand('mceSetContent', false,'"+$PostDescriptionEdit+"')")
      sleep 3
      assert(ie.text_field(:id,/EditNotesBody$/).exists?)
      sleep 3
      ie.text_field(:id,/EditNotesBody$/).value = $EditNotes
      sleep 3
      # Options
      ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.GetTabAtIndex(1))")      
      assert(ie.checkbox(:id,/IsLocked$/).exists?)
      sleep 2
      ie.checkbox(:id,/IsLocked$/).clear
      sleep 2
      assert(ie.select_list(:id,/ctl05_ctl12_ctl02_PinnedPost$/).exists?)
      sleep 2
      ie.select_list(:id,/ctl05_ctl12_ctl02_PinnedPost$/).select('1 Year')
      # Video
      ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.GetTabAtIndex(2))")      
      assert(ie.checkbox(:id,/IncludeVideo$/).exists?)
      ie.checkbox(:id,/IncludeVideo$/).set
      assert(ie.text_field(:id,/VideoUrl$/).exists?)
      ie.text_field(:id,/VideoUrl$/).value = 'http://www.youtube.com/watch?v=Gzj723LkRJY'
      assert(ie.text_field(:id,/VideoDuration$/).exists?)
      ie.text_field(:id,/VideoDuration$/).value = '16:10'
      # Poll
      ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.GetTabAtIndex(3))")      
      assert(ie.checkbox(:id,/IncludePoll$/).exists?)
      ie.checkbox(:id,/IncludePoll$/).set
      assert(ie.text_field(:id,/PollTitle$/).exists?)
      ie.text_field(:id,/PollTitle$/).value = 'Is Watir good for automation ?'
      sleep 2
      ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_PollSubForm_ctl00_PollContainer_ctl00_PollDescription_ctl00_Editor').execCommand('mceSetContent', false,'Watir is web application testing in Ruby')")
      assert(ie.text_field(:id,/NewAnswer$/).exists?)
      ie.text_field(:id,/NewAnswer$/).value = 'Yes'
      assert(ie.button(:id,/AddButton$/).exists?)
      ie.button(:id,/AddButton$/).click
      assert(ie.text_field(:id,/NewAnswer$/).exists?)
      ie.text_field(:id,/NewAnswer$/).value = 'No'
      assert(ie.button(:id,/AddButton$/).exists?)
      ie.button(:id,/AddButton$/).click
      assert(ie.text_field(:id,/NewAnswer$/).exists?)
      ie.text_field(:id,/NewAnswer$/).value = 'Very good'
      assert(ie.button(:id,/AddButton$/).exists?)
      ie.button(:id,/AddButton$/).click
      assert(ie.text_field(:id,/ExpireAfterDays$/).exists?)
      ie.text_field(:id,/ExpireAfterDays$/).value = '50'
      # Related
      ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.GetTabAtIndex(4))")      
      # Preview
      ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_EditorTabs.GetTabAtIndex(5))")      
      assert(ie.button(:id,/PostButton$/).exists?)
      ie.button(:id,/PostButton$/).click 
    end
    def test_20_replyPost
      assert(ie.link(:text,'Reply').exists?)
      ie.link(:text,'Reply').click
      assert(ie.text_field(:id,/PostSubject$/).exists?)
      ie.text_field(:id,/PostSubject$/).value =$Reply
      sleep 3
      ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_ctl00_bcr_bcr_bcr_PostForm_ctl05_PostBody_ctl00_Editor').execCommand('mceSetContent', false,'"+$ReplyContent+"')")
      assert(ie.button(:id,/PostButton$/).exists?)
      ie.button(:id,/PostButton$/).click 
      sleep 5
    end
    def test_21_deletePost
       assert(ie.ul(:class,'ForumPostList').li(:index,1).link(:text,'Delete').exists?)
        ie.ul(:class,'ForumPostList').li(:index,1).link(:text,'Delete').click
       sleep 5
       assert(ie.text_field(:id,'ctl00_ctl00_ctl00_bcr_bcr_bcr_ctl01_ctl03_DeleteReason').exists?)
       sleep 5
       ie.text_field(:id,'ctl00_ctl00_ctl00_bcr_bcr_bcr_ctl01_ctl03_DeleteReason').set($DeleteReason)
       sleep 5
       assert(ie.button(:id,/DeletePost$/).exists?)
       ie.button(:id,/DeletePost$/).click 
     end
     def test_22_DeleteGroup
        test_02_verifyLoginLinksExist
        test_03_navigateToLogin
        test_04_populateLoginForm
        test_05_submitLoginForm
        sleep 5
         ie.goto($SITE_URL+'controlpanel/HubAdmin/hubs.aspx')
        assert(ie.link(:text,'All').exists?)
        ie.link(:text,'All').click
        assert(ie.table(:id,'BlogLists').exists?)
        table1 = ie.table(:id, 'BlogLists')
        rowcount = table1.row_count
        rowcount1 =1
        while rowcount1<=rowcount
            if (table1[rowcount1][1].link(:text,$HubName1).exists?)
              ok =1
               sleep 5
               table1[rowcount1][6].link(:text, 'Delete').click
               break
             end   
            rowcount1=rowcount1+1
        end
      end
      
       def test_23_navigateToDeleteCategory
        ie.goto($SITE_URL+'controlpanel/HubAdmin/groups.aspx')
        sleep 5
        assert(ie.hidden(:id,'ctl00_ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_TaskRegion_CategoriesTree').exists?)
        hiddenvalue=ie.hidden(:id,'ctl00_ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_TaskRegion_CategoriesTree').value
        hiddenvaluearr=hiddenvalue.split('&')
        groupid=hiddenvaluearr[hiddenvaluearr.length-1].split('=')
        ie.ie.Document.parentWindow.execScript("ctl00_ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_TaskRegion_CategoriesTree.SelectNode(ctl00_ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_TaskRegion_CategoriesTree.GetNodeByValue("+groupid[1]+"))")
        sleep 5
        assert(ie.button(:value ,'Delete').exists?)
        ie.button(:value ,'Delete').click
      end
      
       def test_24_searchUser
        ie.goto($SITE_URL +'controlpanel/membership/membersearch.aspx?SelectedNavItem=BrowseMembers')
        assert(ie.text_field(:id,/searchText$/).exists?)
        ie.text_field(:id,/searchText$/).value ="*"
        assert(ie.select_list(:name,/PageList$/).exists?)
        ie.select_list(:name,/PageList$/).select('10')
        sleep 3
        assert(ie.button(:id,/searchButton$/).exists?)
        sleep 2
        ie.button(:id,/searchButton$/).click
      end
      
      def test_25_navigateToDeleteUser
        sleep 5
        table1 = ie.table(:index, 6)
        rowcount = table1.row_count
        rowcount1 =1
        ok =0
        while rowcount1<=rowcount
            if (table1[rowcount1][1].link(:text,$UserName).exists?)
              ok =1
               sleep 5
               table1[rowcount1][5].button(:value, 'Delete').click
               sleep 3
               break
             end   
         rowcount1=rowcount1+1
        end
       if(ok ==0)
         sleep 5
         ie.link(:text,'Next >').click
         sleep 5
         test_25_navigateToDeleteUser
       end
       sleep 5
       assert(ie.frame(:index,1).radio(:id,/AssignToAnonymous$/).exists?)
       ie.frame(:index,1).radio(:id,/AssignToAnonymous$/).set
       sleep 3
       assert(ie.frame(:index,1).button(:id,/DeleteUserButton$/).exists?)
       sleep 3
       ie.frame(:index,1).button(:id,/DeleteUserButton$/).click
       sleep 5
       ie.goto($SITE_URL +'controlpanel/membership/membersearch.aspx?SelectedNavItem=BrowseMembers')
       assert(ie.text_field(:id,/searchText$/).exists?)
       ie.text_field(:id,/searchText$/).value ="*"
       sleep 3
       assert(ie.button(:id,/searchButton$/).exists?)
       sleep 2
       ie.button(:id,/searchButton$/).click 
       if(ie.link(:text,$UserName).exists?)
       puts 'User Not Deleted'
      end   
    end

    
     def test_99_Exit
      ie.close
    end
      
end